/*
    XTU OJ: 1429
    Link: https://acm.xtu.edu.cn/exam/index.php/problem/exam_read/id/1429
    by: fifth_light
*/

#include <stdio.h>

int main(void) {
    int t;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        char grid[10];
        scanf(" %9[0-9]", grid);
        int xline[3];
        int yline[3];
        for (int i = 0; i < 3; i++) {
            int start = i * 3;
            xline[i] = 0;
            for (int j = 0; j < 3; j++) {
                xline[i] += grid[start + j];
            }
        }
        for (int i = 0; i < 3; i++) {
            yline[i] = 0;
            for (int j = 0; j < 3; j++) {
                yline[i] += grid[j * 3 + i];
            }
        }
        int main = grid[0] + grid[4] + grid[8];
        int sub_main = grid[2] + grid[4] + grid[6];
        
        // BREAKPOINT BELOW
        int result = 1;
        do {
            if (main != sub_main) {
                result = 0;
                break;
            }
            for (int i = 0; i < 3; i++) {
                if (main != xline[i]){
                    result = 0;
                    break;
                }
            }
            for (int i = 0; i < 3; i++) {
                if (main != yline[i]){
                    result = 0;
                    break;
                }
            }
        } while(0);
        puts(result ? "Yes" : "No");
    }
    return 0;
}
